Code
remotes::install_github("wilkelab/cowplot")
install.packages("colorspace", repos = "http://R-Forge.R-project.org")
remotes::install_github("clauswilke/colorblindr")在 R 中绘制色盲友好的图
Jie Hua
Aug 28, 2025
Aug 28, 2025
要在 R 中使用色盲友好的调色板,主要需要以下几个包。请务必在保存图片之前,用这些包检查过图。谢谢!
To use colorblind-friendly palettes in R, you mainly need the following packages. Be sure that we checked the plots with these packages before saving the plots. Thank you!
在可用于生产的 R 图形中模拟色盲效果。作者:Claire D. McWhite 与 Claus O. Wilke。
Simulate colorblindness in production-ready R figures. Written by Claire D. McWhite and Claus O. Wilke.
官方仓库:https://github.com/clauswilke/colorblindr
Official repo: https://github.com/clauswilke/colorblindr
也可以通过以下方式安装:(但你需要先安装 pak。
It could also be installed with: (but you need to install pakfirst.
按照官方文档操作很容易,首先创建一个如下的 ggplot 对象:
It is easy to follow the official document, first make a ggplot object like:
然后我们可以用这个包在不同的模拟条件下进行检查:
Then we could use this package to check in different simulations:
也可以在交互式应用中查看它,这里我只展示脚本,它不会为读者打开新的标签页。
It is also possible to inspect it in the interactive app, I just show the script, it will not open a tab for readers.
检查调色板是否存在与色觉缺陷有关的问题
Check Color Palettes for Problems with Color Vision Deficiency
官方仓库:https://github.com/Nowosad/colorblindcheck
Official repo: https://github.com/Nowosad/colorblindcheck
[1] "#FF0000" "#FFDB00" "#49FF00" "#00FF92" "#0092FF" "#4900FF" "#FF00DB"
name n tolerance ncp ndcp min_dist mean_dist max_dist
1 normal 7 12.13226 21 21 12.132257 61.06471 107.63470
2 deuteranopia 7 12.13226 21 19 2.572062 44.29065 85.87461
3 protanopia 7 12.13226 21 17 3.647681 47.63882 83.28286
4 tritanopia 7 12.13226 21 20 2.025647 47.41585 83.77189